unit clsCondPedVenda;

interface

uses Dm,dbtables,biblio,Sysutils;

type
  TCondPedVenda=Class(TObject)
    private
      Ent_codigo     : String;
    public
      Reg_codigo     : String;
      Tab_codigo     : String;
      Cond_preco     : Integer;
      Cond_desc1     : Double;
      Cond_desc2     : Double;
      Cond_desc3     : Double;
      Cond_desc4     : Double;
      Cond_desc5     : Double;
      Cond_acrescimo : Double;
      Cond_aliqfrete : Double;
      function  Gravar(p_Ent_codigo:String):Byte;
      function  Recuperar(p_Ent_codigo:String):Byte;
      function  Excluir(p_Ent_codigo:String):Byte;
//      procedure Consultar(var p_q:TQuery; p_Pro_codigo, p_desc:String);
  end;

implementation

function TCondPedVenda.Gravar;
var tq:TQuery;
begin
  tq:=Tquery.Create(DmInt);
  tq.databasename:=dmint.Db.DatabaseName;
  tq.active:=False;
  tq.sql.clear;
  tq.params.clear;
  tq.sql.add('SELECT * FROM CondPedVenda where Ent_codigo=:k_Ent_codigo');
  tq.parambyname('k_Ent_codigo').asstring:=strzero(p_Ent_codigo,5);
  tq.open;
  if tq.eof then begin
    tq.sql.clear; tq.params.clear;
    tq.sql.add('INSERT INTO CondPedVenda VALUES('+
    ':k_Ent_codigo,'+
    ':k_Reg_codigo,'+
    ':k_Tab_codigo,'+
    ':k_Cond_preco,'+
    ':k_Cond_desc1,'+
    ':k_Cond_desc2,'+
    ':k_Cond_desc3,'+
    ':k_Cond_desc4,'+
    ':k_Cond_desc5,'+
    ':k_Cond_acrescimo,'+
    ':k_Cond_aliqfrete)');
  end else begin
    tq.sql.clear; tq.params.clear;
    tq.sql.add('UPDATE CondPedVenda SET '+
    'Reg_codigo      =:k_Reg_codigo,'+
    'Tab_codigo      =:k_Tab_codigo,'+
    'Cond_preco      =:k_Cond_preco,'+
    'Cond_desc1      =:k_Cond_desc1,'+
    'Cond_desc2      =:k_Cond_desc2,'+
    'Cond_desc3      =:k_Cond_desc3,'+
    'Cond_desc4      =:k_Cond_desc4,'+
    'Cond_desc5      =:k_Cond_desc5,'+
    'Cond_acrescimo  =:k_Cond_acrescimo,'+
    'Cond_aliqfrete  =:k_Cond_aliqfrete '+
    'WHERE Ent_codigo=:k_Ent_codigo');
  end;
  tq.parambyname('k_Ent_codigo').asstring:=strzero(p_Ent_codigo,5);
  tq.parambyname('k_Reg_codigo').asstring:=strzero(Reg_codigo,3);
  tq.parambyname('k_Tab_codigo').asstring:=strzero(Tab_codigo,3);
  tq.parambyname('k_Cond_preco').asinteger:=Cond_preco;
  tq.parambyname('k_Cond_desc1').asfloat:=Cond_desc1;
  tq.parambyname('k_Cond_desc2').asfloat:=Cond_desc2;
  tq.parambyname('k_Cond_desc3').asfloat:=Cond_desc3;
  tq.parambyname('k_Cond_desc4').asfloat:=Cond_desc4;
  tq.parambyname('k_Cond_desc5').asfloat:=Cond_desc5;
  tq.parambyname('k_Cond_acrescimo').asfloat:=Cond_acrescimo;
  tq.parambyname('k_Cond_aliqfrete').asfloat:=Cond_aliqfrete;
  tq.close;
  tq.execsql;
  result:=1;
  tq.Free;
end;

function TCondPedVenda.Recuperar;
var tq:TQuery;
begin
  tq:=Tquery.Create(dmint);
  tq.databasename:=DmInt.Db.DatabaseName;
  tq.active:=False;
  tq.sql.clear;
  tq.sql.add('SELECT * FROM CondPedVenda where Ent_codigo=:k_Ent_codigo');
  tq.params[0].asstring:=strzero(p_Ent_codigo,5);
  tq.open;
  Ent_codigo  :=p_Ent_codigo;
  if tq.eof then begin
    Reg_codigo     := '';
    Tab_codigo     := '';
    Cond_preco     := 0;
    Cond_desc1     := 0;
    Cond_desc2     := 0;
    Cond_desc3     := 0;
    Cond_desc4     := 0;
    Cond_desc5     := 0;
    Cond_acrescimo := 0;
    Cond_aliqfrete := 0;
    Result:=0;
  end else begin
    Reg_codigo     :=tq.fieldbyname('Reg_codigo').asstring;
    Tab_codigo     :=tq.fieldbyname('Tab_codigo').asstring;
    Cond_preco     :=tq.fieldbyname('Cond_preco').asinteger;
    Cond_desc1     :=tq.fieldbyname('Cond_desc1').asfloat;
    Cond_desc2     :=tq.fieldbyname('Cond_desc2').asfloat;
    Cond_desc3     :=tq.fieldbyname('Cond_desc3').asfloat;
    Cond_desc4     :=tq.fieldbyname('Cond_desc4').asfloat;
    Cond_desc5     :=tq.fieldbyname('Cond_desc5').asfloat;
    Cond_acrescimo :=tq.fieldbyname('Cond_acrescimo').asfloat;
    Cond_aliqfrete :=tq.fieldbyname('Cond_aliqfrete').asfloat;
    Result:=1;
  end;
  tq.Close;
  tq.Free;
end;

function TCondPedVenda.Excluir;
var tq:TQuery;
begin
  tq:=Tquery.Create(dmint);
  tq.databasename:=dmint.db.databasename;
  tq.active:=False;
  tq.close;
  tq.sql.Clear;
  tq.params.clear;
  tq.sql.add('DELETE FROM CondPedVenda WHERE Ent_codigo=:k_Ent_codigo');
  tq.parambyname('k_Ent_codigo').asstring:=strzero(p_Ent_codigo,5);
  tq.execSQL;
  Result:=1;
  tq.close;
  tq.Free;
end;

end.
